package rexsee.core.application;

import rexsee.core.browser.Browser;
import rexsee.core.browser.clazz.JavascriptInterface;
import android.content.Context;
import android.content.res.Configuration;

public class RexseeConfiguration implements JavascriptInterface {

	public static final String INTERFACE_NAME = "Configuration";

	@Override
	public String getInterfaceName() {
		return mBrowser.application.resources.prefix + INTERFACE_NAME;
	}
	@Override
	public JavascriptInterface getInheritInterface(Browser childBrowser) {
		return this;
	}
	@Override
	public JavascriptInterface getNewInterface(Browser childBrowser) {
		return new RexseeConfiguration(childBrowser);
	}

	private final Context mContext;
	private final Browser mBrowser;
	public RexseeConfiguration(Browser browser) {
		mContext = browser.getContext();
		mBrowser = browser;
	}

	public static String getOrientation(int orientation) {
		switch (orientation) {
			case Configuration.ORIENTATION_LANDSCAPE :
				return "landscape";
			case Configuration.ORIENTATION_PORTRAIT :
				return "portrait";
			case Configuration.ORIENTATION_SQUARE :
				return "square";
			default :
				return "undefined";
		}
	}

	//JavaScript Interface

	public float getFontScale() {
		Configuration c = mContext.getResources().getConfiguration();
		return c.fontScale;
	}
	public boolean isHardKeyboardHidden() {
		Configuration c = mContext.getResources().getConfiguration();
		return (c.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) ? true : false;
	}
	public boolean isKeyboardHidden() {
		Configuration c = mContext.getResources().getConfiguration();
		return (c.keyboardHidden == Configuration.KEYBOARDHIDDEN_YES) ? true : false;
	}
	public String getKeyboard() {
		Configuration c = mContext.getResources().getConfiguration();
		switch (c.keyboard) {
			case Configuration.KEYBOARD_12KEY :
				return "12";
			case Configuration.KEYBOARD_QWERTY :
				return "qwerty";
			default :
				return "none";
		}
	}
	public String getNavigation() {
		Configuration c = mContext.getResources().getConfiguration();
		switch (c.navigation) {
			case Configuration.NAVIGATION_DPAD :
				return "dpad";
			case Configuration.NAVIGATION_TRACKBALL :
				return "trackball";
			case Configuration.NAVIGATION_WHEEL :
				return "wheel";
			default :
				return "none";
		}

	}
	public String getOrientation() {
		return getOrientation(mContext.getResources().getConfiguration().orientation);
	}
	public String getTouchScreen() {
		Configuration c = mContext.getResources().getConfiguration();
		switch (c.touchscreen) {
			case Configuration.TOUCHSCREEN_FINGER :
				return "finger";
			case Configuration.TOUCHSCREEN_STYLUS :
				return "stylus";
			default :
				return "none";
		}

	}

	/*
	public boolean isNavigationHidden() {
		Configuration c = mContext.getResources().getConfiguration();
		return (c.navigationHidden == Configuration.NAVIGATIONHIDDEN_YES) ? true : false;
	}
	public String getScreenLayoutSize() {
		Configuration c = mContext.getResources().getConfiguration();
		switch (c.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) {
			case Configuration.SCREENLAYOUT_SIZE_LARGE :
				return "large";
			case Configuration.SCREENLAYOUT_SIZE_SMALL :
				return "small";
			default :
				return "normal";
		}

	}
	public boolean isScreenLayoutLong() {
		Configuration c = mContext.getResources().getConfiguration();
		return ((c.screenLayout & Configuration.SCREENLAYOUT_LONG_MASK) == Configuration.SCREENLAYOUT_LONG_YES) ? true : false;
	}
	*/
}
